// Copyright (c) 2008 Matthew Johnson
// Licensed under the MIT License (see license.txt)
package actionml.animation {
	import flash.display.DisplayObject;
	import flash.geom.ColorTransform;
	class ColorTransformTweenRenderer extends ColorPropertyTweenRenderer {
		public static function isApplicable(targetClass:Class, property:String) {
			return property == "color" && targetClass["getClassHierarchy"]().contains(DisplayObject);
		}
		public function ColorTransformTweenRenderer(target:Object, property:String, start:Number, end:Number, tween:Tween) {
			super(target, property, start, end, tween);
		}		
		internal override function renderFrame(rc:RenderContext) {
			var ct:ColorTransform = DisplayObject(_target).transform.colorTransform || new ColorTransform();
			var mult:Number = _tween.ease(rc.time - _tween.startTime, 1, -1, _tween.renderDuration);
			ct.redMultiplier = mult;
			ct.greenMultiplier = mult;
			ct.blueMultiplier = mult;
			ct.redOffset = _tween.ease(rc.time - _tween.startTime, _startRed, _redDistance, _tween.renderDuration);
			ct.greenOffset = _tween.ease(rc.time - _tween.startTime, _startGreen, _greenDistance, _tween.renderDuration);
			ct.blueOffset = _tween.ease(rc.time - _tween.startTime, _startBlue, _blueDistance, _tween.renderDuration);
			DisplayObject(_target).transform.colorTransform = ct;
		}
		internal override function renderLastFrame(rc:RenderContext) {
			var ct:ColorTransform = DisplayObject(_target).transform.colorTransform || new ColorTransform();
			ct.redMultiplier = 0;
			ct.greenMultiplier = 0;
			ct.blueMultiplier = 0;
			ct.redOffset = _startRed + _redDistance;
			ct.greenOffset = _startGreen + _greenDistance;
			ct.blueOffset = _startBlue + _blueDistance;
			DisplayObject(_target).transform.colorTransform = ct;
		}
	}
}